//922.按奇偶排序数组II
//https://leetcode.cn/problems/sort-array-by-parity-ii/
class Solution {
public:
    vector<int> sortArrayByParityII(vector<int>& nums) {
        int n = nums.size();
        int k = 1; //奇数下标
        for(int i = 0;i<n;i+=2)
        {
            //将所有偶数下标的数字置为偶数
            if(nums[i]%2==1)
            {
                while(k<n && nums[k]%2==1) k+=2;
                swap(nums[i],nums[k]); //找到了就交换
            }
        }
        return nums;
    }
};